import datetime
# from django.utils import timezone
from django.db import models

# Create your models here.
class VastConnect(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField('Username', max_length=30)
    password = models.CharField('Password', max_length=250)
    firstname = models.CharField('First Name', max_length=150)
    middlename = models.CharField('Middle Name', max_length=30)
    lastname = models.CharField('Last Name', max_length=150)
    date_joined = models.DateTimeField('Date Joined');
    email = models.EmailField('Email Address')

    def _get_full_name_(self):
        ''' Returns the Users Full Name '''
        return '%s %s %s' % (self.firstname, self.middlename, self.lastname)

    def __unicode__(self):
        return self.username

class VastGroup(models.Model):
    name = models.CharField('Group Name', max_length=40)
    members = models.ManyToManyField(VastConnect, through='VastPIN')

    def __unicode__(self):
        return self.title

class VastPIN(models.Model):
    GENDER_CHOICE = (
        (u'M', u'Male'),
        (u'F', u'Female'),
    )

    STATUS_CHOICE = (
        (u'S', u'Single'),
        (u'M', u'Married'),
        (u'D', u'Divorce'),
        (u'U', u'Unapplicable'),
    )

    COUNTRY_CHOICE = (
        (u'AU', u'Australia'),
        (u'PH', u'Philippines'),
        (u'SG', u'Singapore'),
        (u'US', u'United States'),
        (u'UK', u'Great Britain'),
        (u'ZA', u'South Africa'),
    )

    user = models.ForeignKey(VastConnect, verbose_name='Username')
    group = models.ForeignKey(VastGroup, verbose_name='Group Membership')
    address = models.CharField('House Address', max_length=250)
    telephone = models.CharField('Phone Number', max_length=25)
    gender = models.CharField('Gender', max_length=2, choices=GENDER_CHOICE)
    status = models.CharField('Social Status', max_length=2, choices=STATUS_CHOICE)
    zipcode = models.IntegerField('Zip Code', max_length=6)
    country = models.CharField('Country', max_length=3, choices=COUNTRY_CHOICE)

    def __unicode__(self):
        return self.user

class Blog(models.Model):
    title = models.CharField('Topic Title', max_length=250)
    body = models.TextField('Topic Body')
    date_created = models.DateTimeField('Date Created')

    def __unicode__(self):
        return self.title

class BlogTags(models.Model):
    name = models.CharField('Tags', max_length=250)
    posts = models.ManyToManyField(Blog, through='BlogPost')

class BlogPost(models.Model):
    title = models.ForeignKey(Blog, verbose_name='Post Title')
    tags = models.ForeignKey(BlogTags, verbose_name='Tags')
    author = models.ForeignKey(VastConnect, verbose_name='Author')

    def __unicode__(self):
        return self.title

class MangaDatabase(models.Model):
    name = models.CharField('Novel Title', max_length=250)
    altname = models.CharField('Alternate Novel Title', max_length=250)

    def __unicode__(self):
        return self.name

class MangaGenre(models.Model):
    name = models.CharField('Novel Genre', max_length=250)
    members = models.ManyToManyField(MangaDatabase, through='MangaInformation')

    def __unicode__(self):
        return self.name

class MangaAuthors(models.Model):
    name = models.CharField('Author', max_length=250)
    serialized = models.ManyToManyField(MangaDatabase, through='MangaInformation')

    def __unicode__(self):
        return self.name

class MangaPublishers(models.Model):
    name = models.CharField('Publisher', max_length=250)
    serialized = models.ManyToManyField(MangaDatabase, through='MangaInformation')

    def __unicode__(self):
        return self.name

class MangaInformation(models.Model):
    name = models.ForeignKey(MangaDatabase, verbose_name='Novel Title')
    genre = models.ForeignKey(MangaGenre, verbose_name='Novel Genre')
    description = models.TextField('Description')
    author = models.ForeignKey(MangaAuthors, verbose_name='Author')
    status = models.CharField('Status', max_length=250)
    yearstr = models.CharField('Year Started', max_length=250)
    yearend = models.CharField('Year Ended', max_length=250)
    publisher = models.ForeignKey(MangaPublishers, verbose_name='Novel Publisher')

    def __unicode__(self):
        return self.name

